﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Entity;
using DAL;
using System.Collections;
using System.Data.SqlClient;
using System.Data;

namespace BLL
{
    public class StudentService
    {
        private StudentsDAL studentsDAL = new StudentsDAL();

        /// <summary>
        /// 根据学生对象来添加学生
        /// </summary>
        /// <param name="student">学生对象</param>
        public void CreateStudent(BoStudents student)
        {
            student.STU_ID = System.Guid.NewGuid().ToString();
            studentsDAL.Insert(student);
        }

        /// <summary>
        /// 根据学生对象来更新学生
        /// </summary>
        /// <param name="student">学生对象</param>
        public void UpdateStudent(BoStudents student)
        {
            studentsDAL.Update(student);
        }

        /// <summary>
        /// 根据学生对象来删除相应id的学生
        /// </summary>
        /// <param name="student">学生对象</param>
        public void DeleteStudent(BoStudents student)
        {
            studentsDAL.Delete(student.STU_ID);
        }
        /// <summary>
        /// 根据学生的id来拿到学生对象
        /// </summary>
        /// <param name="id">学生id</param>
        /// <returns>返回学生对象</returns>
        public BoStudents getStudent(string id)
        {
            return studentsDAL.GetModel(id);
        }
        /// <summary>
        /// 通过学生id来删除学生
        /// </summary>
        /// <param name="stuId"></param>
        public void DeleteStudent(string stuId)
        {
            studentsDAL.Delete(stuId);
        }
           /// <summary>
        /// 根据学号来获取一条记录
        /// </summary>
        /// <param name="STU_Code">学号</param>
        /// <returns></returns>
        public BoStudents GetModelByCode(string STU_Code)
        {
           return studentsDAL.GetModelByCode(STU_Code);
        }
        /// 根据用户名来获取一条记录
        /// </summary>
        /// <param name="STU_Code">学号</param>
        /// <returns></returns>
        public BoStudents GetModelByUserName(string STU_Name)
        {
            return studentsDAL.GetModelByUserName(STU_Name);
        }
        /// <summary>
        /// 根据学生的对象来核对是否有此学生
        /// </summary>
        /// <param name="student">学生对象</param>
        /// <returns>返回bool值</returns>
        public BoStudents CheckStudent(BoStudents student)
        {
            return studentsDAL.CheckStudent(student);
        }

        /// <summary>
        /// 根据班级id来删除学生
        /// </summary>
        /// <param name="classId"></param>
        public void DeleteByClssId(string classId) 
        {
            studentsDAL.DeleteByClssId(classId);
        }


        public IList<BoStudents> getStudentsByClass(string classId)
        {
            return studentsDAL.GetStudentsByClass(classId);
        }
        public IList<BoStudents> getStudentsByGroups(string groupId)
        {
            return studentsDAL.GetStudentsByGroup(groupId);
        }
        public IList<BoStudents> GetStudentsByAcademy(string academyId)
        {
            return studentsDAL.GetStudentsByAcademy(academyId);
        }
        /// <summary>
        /// 获取所有符合条件的学生数据
        /// </summary>
        /// <param name="sqlcon">sql条件</param>
        /// <returns>返回相应的数据集</returns>
        public List<BoStudents> GetAllStudents(object sqlcon)
        {
            return studentsDAL.GetAllStudents(sqlcon);
        }
        /// <summary>
        /// 假批量删除一批学生
        /// </summary>
        /// <param name="StudentsId">学生id的数组</param>
        public int FDleteMoreStudents(ArrayList StudentsIdArray)
        {
            return studentsDAL.FDleteMoreStudents(StudentsIdArray);
        }
        /// <summary>
        /// 批量删除一批学生
        /// </summary>
        /// <param name="StudentsId">学生id的数组</param>
        public int DleteMoreStudents(ArrayList StudentsIdArray)
        {
            return studentsDAL.DleteMoreStudents(StudentsIdArray);
        }
        /// <summary>
        /// 根据多个班级id来删除删除一批学生
        /// </summary>
        /// <param name="ClassIdArray">班级id的数组</param>
        public void DleteMoreByClassArr(ArrayList classesArray)
        {
             studentsDAL.DleteMoreByClassArr(classesArray);
        }
          /// <summary>
        /// 根据学生id来从学生视图中获取单条数据
        /// </summary>
        /// <param name="stundetId"></param>
        /// <returns></returns>
        public BoStudents GetV_Student(string studentId) {
            return studentsDAL.GetV_Student(studentId);
        }
        /// <summary>
        /// 通过学生的学号来获得相应的数据
        /// </summary>
        /// <param name="studnentCode">学号</param>
        /// <returns>返回学生对象</returns>
        public BoStudents GetV_studentByCode(string studnentCode)
        {
            return studentsDAL.GetV_studentByCode(studnentCode);
        }


         /// <summary>
        /// 通过学号来获取相应的学生对象
        /// </summary>
        /// <param name="studnetCode">学号</param>
        /// <returns>返回学生对象</returns>
        public BoStudents getStudentByCode(string studnetCode)
        {
            return studentsDAL.getStudentByCode(studnetCode);
        }
        /// <summary>
        /// 根据条件来获得视图v_StudentToContest表格
        /// </summary>
        /// <param name="constr">条件</param>
        /// <returns>返回表格</returns>
        public DataTable Getv_StudentToContest(string constr)
        {
            return studentsDAL.Getv_StudentToContest(constr);
        }

        public void RemoveStudents(BoStudents model)
        {
            studentsDAL.Delete(model.STU_ID);
        }
    }
}
